import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Item {
    ScrollView {
        anchors.fill: parent

        ListView {
            id: list_view
            anchors.fill: parent
            spacing: 4
            clip: true
            model: Kontrast.color_pairs
            boundsMovement: Flickable.StopAtBounds

            delegate: Rectangle {
                id: rect
                required property int index
                required property string modelData

                function text_color() {return modelData.split(';')[0]}

                function background_color() {return modelData.split(';')[1]}

                width: ListView.view.width
                height: 205
                color: background_color()

                RoundButton {
                    width: 35
                    height: 35
                    anchors.right: parent.right
                    anchors.top: parent.top
                    anchors.rightMargin: 10
                    anchors.topMargin: 10
                    icon.source: './icons/actions/edit-delete-remove-symbolic.png'
                    radius: 5
                    onClicked: Kontrast.remove_favorite(index)
                }

                ColumnLayout {
                    anchors.fill: parent
                    anchors.margins: 10
                    Label {
                        text: qsTr('鲁迅')
                        color: rect.text_color()
                        font.pixelSize: 20
                        Layout.fillWidth: true

                    }
                    Label {
                        text: qsTr('愿中国青年都摆脱冷气，只是向上走，不必听自暴自弃者流的话。能做事的做事，能发声的发声。有一分热，发一分光，就令萤火一般，也可以在黑暗里发一点光，不必等候炬火。')
                        color: rect.text_color()
                        wrapMode: Text.WordWrap
                        font.pixelSize: 16
                        Layout.fillWidth: true
                        Layout.rightMargin: 50
                    }
                    RowLayout {
                        RoundButton {
                            text: 'Text: '+rect.text_color()
                            icon.source: './icons/actions/edit-copy-symbolic.png'
                            Layout.preferredWidth: 110
                            radius: 5
                            onClicked: Kontrast.copy(rect.text_color())
                        }
                        RoundButton {
                            text: 'Background: '+rect.background_color()
                            icon.source: './icons/actions/edit-copy-symbolic.png'
                            Layout.preferredWidth: 150
                            radius: 5
                            onClicked: Kontrast.copy(rect.background_color())
                        }
                    }
                    RoundButton {
                        text: 'Apply'
                        icon.source: './icons/actions/dialog-ok-apply-symbolic.png'
                        Layout.preferredWidth: 75
                        radius: 5
                        onClicked: {
                            Kontrast.color = rect.text_color()
                            Kontrast.bkcolor = rect.background_color()
                            pages.currentIndex = 0
                        }
                    }
                }
            }
        }
    }
}
